<?php

namespace app\controllers;

use app\librarys\BaseController;
use app\librarys\FileService;
use app\librarys\Inteface;
use Yii;
use yii\data\Pagination;
use app\models\Goods;
use app\models\Institution;
use app\models\Manager;
use app\models\InstitutionUpdateRecord;
use app\librarys\Tools;
use app\librarys\qcloud_cos\Conf;
use app\librarys\qcloud_cos\Cosapi;

/**
 * 商品管理
 * Class GoodsController
 * @package app\controllers
 */
class GoodsController extends BaseController
{
    /**
     * 系统商品池主页 systgoods
     * @return string
     */
    public function actionSystgoods()
    {
        $page = Yii::$app->request->get('page', 1);
        $institution_code = '0';//系统商品池 机构默认为0
        $code = Yii::$app->request->get('code', '');
        $name = Yii::$app->request->get('name', '');
        $group_code = Yii::$app->request->get('group_code', '');
        $group_item_name = Yii::$app->request->get('group_item_name', '');
        $brand = Yii::$app->request->get('brand', '');
        $type = Yii::$app->request->get('type', '');
        $is_enabled = Yii::$app->request->get('enabled', '-1');//下拉类参数默认为-1 因为在页面 无选择时是不传入参数的（由于返回参数为空的情况页面默认为0 与实际选择传0冲突）
        $is_shelved = Yii::$app->request->get('shelved', '-1');
        $is_activity = Yii::$app->request->get('activity', '-1');
        $is_trusteeship = Yii::$app->request->get('trusteeship', '-1');
        $jg_form = Yii::$app->request->get('jg_form', '');//价格区间 起始
        $jg_to = Yii::$app->request->get('jg_to', '');//价格区间 结束

        //取得产品总数 -用于分页
        $DataCount = Goods::getGoodsCountByfilters($institution_code, $code, $name, $group_code, $group_item_name, $brand, $type, $is_enabled, $is_shelved, null, null, null, $is_activity, $is_trusteeship,null,$jg_form,$jg_to);
        $PageSize = 10;

        $pagination = new Pagination([
            'defaultPageSize' => $PageSize,
            'totalCount' => $DataCount,
        ]);

        //查询结果
        $list = Goods::getGoodsListByfilters($institution_code, $code, $name, $group_code, $group_item_name, $brand, $type, $is_enabled, $is_shelved, null, null, null, $is_activity, $is_trusteeship, null, $page, $PageSize,$jg_form,$jg_to);
        //返回结果
        return $this->render('systgoods', ['pagination' => $pagination, 'list' => $list
            , 'code' => $code, 'name' => $name, 'group_code' => $group_code, 'group_item_name' => $group_item_name, 'brand' => $brand, 'type' => $type
            , 'enabled' => $is_enabled, 'shelved' => $is_shelved, 'activity' => $is_activity, 'trusteeship' => $is_trusteeship, 'jg_form' => $jg_form, 'jg_to' => $jg_to]);
    }

    /**
     * syngoods
     * 从业务系统同步产品信息
     * @return string
     */
    public function actionSyngoodsHandler()
    {
        $msg = "";
        $flag = 0;
        //同步产品
        Goods::synGoods('Y');
        //同步产品图片
        Goods::synGoodsImage();
        //0：正常 !0:其它状态
        return $this->renderJson(null, $flag, $msg);
    }

    /**
     * syngoods
     * 从业务系统同步产品基础信息
     * @return string
     */
    public function actionSyngoodsBaseinfoHandler()
    {
        $msg = "";
        $flag = 0;
        //同步产品
        Goods::synGoods('N');
        //0：正常 !0:其它状态
        return $this->renderJson(null, $flag, $msg);
    }

    /**
     * syngoods
     * 从业务系统同步产品详情描述信息
     * @return string
     */
    public function actionSyngoodsHtmlHandler()
    {
        $msg = "";
        $flag = 0;
        //同步产品
        Goods::synGoodsHtml();
        //0：正常 !0:其它状态
        return $this->renderJson(null, $flag, $msg);
    }

    /**
     * syngoods
     * 从业务系统同步产品图片信息
     * @return string
     */
    public function actionSyngoodsImageHandler()
    {
        $msg = "";
        $flag = 0;
        //同步产品图片
        Goods::synGoodsImage();
        //0：正常 !0:其它状态
        return $this->renderJson(null, $flag, $msg);
    }

    /**
     * 查询系统产品详情 goods-detail-part-view
     * @return string
     */
    public function actionGoodsDetailPartView()
    {
        $request = Yii::$app->request;
        $goods_code = $request->post("goods_code");
        $institution_code = '0';

        $goods_detail = Goods::getGoodsInfoByCode($institution_code, $goods_code);

        return $this->renderPartial('goods-detail-part-view', ['goods' => $goods_detail]);
    }

    /**
     * 查询产品HTML详情 goods-htmldetail-part-view
     * @return string
     */
    public function actionGoodsHtmldetailPartView()
    {
        $request = Yii::$app->request;
        $goods_code = $request->post("goods_code");
        $institution_code = $request->post("institution_code");
        $goods_img1 = '';
        $goods_img2 = '';
        $detail_html = '';
        $goods_img1 = Goods::getGoodsImage($goods_code, 1);
        $goods_img2 = Goods::getGoodsImage($goods_code, 2);
        if ($goods_img1 != false) {
            $goods_img1 = $goods_img1[0]['image_url'];
        }
        $goods_detail = Goods::getGoodsInfoByCode($institution_code, $goods_code);
        if ($goods_detail != false) {
            $detail_html = $goods_detail['detail_html'];
        }
        return $this->renderPartial('goods-htmldetail-part-view', ['goods_img' => $goods_img1, 'goods_img_list' => $goods_img2, 'detail_html' => $detail_html]);
    }

    /**
     * 机构商品池主页 instgoods
     * @return string
     */
    public function actionInstgoods()
    {
        $page = Yii::$app->request->get('page', 1);
        $institution_code = Manager::getCurrentManager()['institution_code'];
        if ($institution_code == '0') {
            $institution_code = Yii::$app->request->get('inst', '');
        }
        $code = Yii::$app->request->get('code', '');
        $name = Yii::$app->request->get('name', '');
        $group_code = Yii::$app->request->get('group_code', '');
        $group_item_name = Yii::$app->request->get('group_item_name', '');
        $brand = Yii::$app->request->get('brand', '');
        $type = Yii::$app->request->get('type', '');
        $is_enabled = Yii::$app->request->get('enabled', '-1'); //下拉类参数默认为-1 因为在页面 无选择时是不传入参数的（由于返回参数为空的情况页面默认为0 与实际选择传0冲突）
        $is_shelved = Yii::$app->request->get('shelved', '-1');
        $is_newest = Yii::$app->request->get('newest', '-1');
        $is_hot = Yii::$app->request->get('hot', '-1');
        $is_top = Yii::$app->request->get('top', '-1');
        $is_activity = Yii::$app->request->get('activity', '-1');
        $is_trusteeship = Yii::$app->request->get('trusteeship', '-1');//是否托管商品
        $is_pcr = Yii::$app->request->get('is_pcr', '-1');//是否结算价格有变更
        $jsjg_form = Yii::$app->request->get('jsjg_form', '');//结算价格区间 起始
        $jsjg_to = Yii::$app->request->get('jsjg_to', '');//结算价格区间 结束
        $jgdb1 = Yii::$app->request->get('jgdb1', '-1');//结算价格 销售价格 条件
        $jgdb2 = Yii::$app->request->get('jgdb2', '-1');//结算价格 供应价格 条件
        $jgdb3 = Yii::$app->request->get('jgdb3', '-1');//销售价格 供应价格 条件

        $PageSize = 10;
        $DataCount = 0;
        $list = null;
        $isSupplyPriceChange = 0;

        //取得产品总数 -用于分页
        $DataCount = Goods::getGoodsCountByfilters($institution_code, $code, $name, $group_code, $group_item_name, $brand, $type, $is_enabled, $is_shelved, $is_newest, $is_hot, $is_top, $is_activity, $is_trusteeship, $is_pcr, $jsjg_form, $jsjg_to, $jgdb1, $jgdb2, $jgdb3);
        //查询结果
        $list = Goods::getGoodsListByfilters($institution_code, $code, $name, $group_code, $group_item_name, $brand, $type, $is_enabled, $is_shelved, $is_newest, $is_hot, $is_top, $is_activity, $is_trusteeship, $is_pcr, $page, $PageSize, $jsjg_form, $jsjg_to, $jgdb1, $jgdb2, $jgdb3);

        if ($institution_code != null && $institution_code != '') {
            //查询当前机构下是否有结算价格变动
            $pcr = Goods::getInstGoodsSupplyPriceCRecords($institution_code);
            if ($pcr != null && $pcr != '') {
                $isSupplyPriceChange = 1;
            }
        }

        $pagination = new Pagination([
            'defaultPageSize' => $PageSize,
            'totalCount' => $DataCount,
        ]);

        //返回时如果未选择机构则返回当前用户所属机构
        if ($institution_code == null || $institution_code == '') {
            //当前用户的机构-----------------------------------------------
            $current_console_user = Manager::getCurrentManager();
            $institution = $current_console_user['institution_code'];
            //---------------------------------------------------------------
            $institution_code = $institution;
        }
        //返回结果
        return $this->render('instgoods', ['pagination' => $pagination, 'list' => $list
            , 'institution_code' => $institution_code, 'code' => $code, 'name' => $name, 'group_code' => $group_code, 'group_item_name' => $group_item_name, 'brand' => $brand, 'type' => $type
            , 'enabled' => $is_enabled, 'shelved' => $is_shelved, 'newest' => $is_newest, 'hot' => $is_hot, 'top' => $is_top, 'activity' => $is_activity, 'trusteeship' => $is_trusteeship, 'is_pcr' => $is_pcr
            , 'pcr' => $isSupplyPriceChange, 'jsjg_form' => $jsjg_form, 'jsjg_to' => $jsjg_to, 'jgdb1' => $jgdb1, 'jgdb2' => $jgdb2, 'jgdb3' => $jgdb3]);
    }

    /**
     * syn-instgoods-handler
     * 同步机构产品
     * @return string
     */
    public function actionSynInstgoodsHandler()
    {
        $msg = "";
        $flag = 0;
        //当前机构的上级机构产品信息
        $request = Yii::$app->request;
        $institution_code = $request->post("institution_code");

        if ($institution_code != null && $institution_code != '') {
            $parentInstGoodsCount = Goods::getParentInstGoodsCountByInstcode($institution_code);
            if ($parentInstGoodsCount > 0) {
                //同步机构产品
                $flag = Goods::synInstGoods($institution_code);
            } else {
                $flag = 1;
                $msg = "上级机构产品池无数据，同步失败！";
            }
        }

        return $this->renderJson(null, $flag, $msg);
    }

    /**
     * import-institution-goods-confirm
     * 机构产品池-导入确认
     * @return string
     */
    public function actionImportInstitutionGoodsConfirmHandler()
    {
        $request = Yii::$app->request;
        $institution_code = $request->post("institution_code");
        $importGoodsList = $request->post("importGoodsList");

        $rtstatus = 0;
        if ($importGoodsList != null && $importGoodsList != '') {
            $rtstatus = Goods::importInstitutionGoods($institution_code, $importGoodsList);
        }

        return $this->renderJson('', $rtstatus);
    }

    /**
     * import-institution-goods
     * 机构产品池-导入
     */
    public function actionImportInstitutionGoods()
    {
        $status = 0;
        $msg = '';
        $goods_list = array();
        $request = Yii::$app->request;
        $upload_institution_code = $request->post("upload_institution_code");
        $file = $_FILES['file']['name'];
        if (empty($file)) {
            $status = 1;
            $msg = json_encode("请选择要上传的文件");
        } else {
            $file_info = pathinfo($file);
            $file_ext = $file_info['extension'];
            if (!in_array($file_ext, array('xls', 'xlsx'))) {
                $status = 1;
                $msg = json_encode("文件类型不正确，仅支持xls,xlsx类型的文件！");
            } else {
                $objPHPExcel = \PHPExcel_IOFactory::load($_FILES['file']['tmp_name']);
                $sheet = $objPHPExcel->getSheet(0);
                $highestRow = $sheet->getHighestRow();       //取得总行数
                $highestColumn = $sheet->getHighestColumn(); //取得总列

                if ($highestRow > 5002) {
                    $status = 2;
                    $msg = json_encode("一次导入数据不能超过5000条记录！");
                } else {

                    for ($j = 2; $j <= $highestRow; $j++)                      //从第二行开始读取数据
                    {
                        $is_error = 0;
                        $v = array();

                        for ($k = 'A'; $k <= $highestColumn; $k++)            //从A列读取数据
                        {
                            $value = $objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue();//读取单元格
                            $v['error'] = "";

                            //获取数据
                            switch ($k) {
                                case 'A':
                                    $v['goods_code'] = trim($value);
                                    break;
                                case 'B':
                                    $v['goods_name'] = trim($value);
                                    break;
                                case 'C':
                                    $v['settlement_price'] = trim($value);
                                    break;
                                case 'D':
                                    $v['selling_price'] = trim($value);
                                    break;
                                case 'E':
                                    $v['supply_price'] = trim($value);
                                    break;
                                case 'F':
                                    $v['is_enabled'] = trim($value);
                                    break;
                                case 'G':
                                    $v['is_shelved'] = trim($value);
                                    break;
                                case 'H':
                                    $v['is_newest'] = trim($value);
                                    break;
                                case 'I':
                                    $v['is_hot'] = trim($value);
                                    break;
                                case 'J':
                                    $v['is_top'] = trim($value);
                                    break;
                                case 'K':
                                    $v['is_show'] = trim($value);
                                    break;
                            }

                        }

                        $errormsg = "";
                        //检查数据有效性

                        if ($upload_institution_code != null && $upload_institution_code != '' && $v['goods_code'] != null && $v['goods_code'] != '') {
                            $hidegoodscode = Goods::getHideGoodsByChildInstAndCode($upload_institution_code, $v['goods_code']);
                            if ($hidegoodscode != null && $hidegoodscode != '') {
                                $errormsg = $errormsg . ">此商品已被上级机构设置为不可用【" . $v['goods_code'] . "】,不可导入！";
                            }

                            $goodscode = Goods::getGoodsCodeByChildInstAndCode($upload_institution_code, $v['goods_code']);
                            if ($goodscode == null || $goodscode == '') {
                                $sign = "";
                                if ($errormsg != null && $errormsg != '') {
                                    $sign = "<br>";
                                }
                                $errormsg = $errormsg . $sign . ">上级机构不存在商品【" . $v['goods_code'] . "】,不可导入！";
                            }
                        }

                        if ($errormsg != null && $errormsg != '') {
                            $v['error'] = $errormsg;
                        }

                        $goods_list[] = $v;
                    }
                }
            }
        }

        return $this->renderJson(['goods_list' => $goods_list], $status, $msg);
    }

    /**
     * update-inst-goods-handler
     * @return string
     */
    public function actionUpdateInstGoodsHandler()
    {
        $this->layout = false;
        $request = Yii::$app->request;
        $institution_code = $request->post("institution_code");
        $goods_code = $request->post("goods_code");
        $settlement_price = $request->post("settlement_price");
        $selling_price = $request->post("selling_price");
        $supply_price = $request->post("supply_price");
        $is_enabled = $request->post("is_enabled");
        $is_shelved = $request->post("is_shelved");
        $shelve_datetime = $request->post("shelve_datetime");
        $is_newest = $request->post("is_newest");
        $is_hot = $request->post("is_hot");
        $is_top = $request->post("is_top");
        $is_show = $request->post("is_show");
        $category_code = $request->post("category_code");

        $rtstatus = 0;
        $msg = '';

        //如果修改的此产品为上架或启用 则需判断系统产品池中此产品是为上架并且启用状态如果是则允许修改 不是则不允许修改 提示此产品已停产不允许上架
        if($is_enabled==1 || $is_shelved==1){
            $canshelved = Goods::checkGoodsCanShelved($goods_code);
            //如果查询出不可以启用上架则不允许保存数据
            if(!$canshelved){
                $rtstatus = 1;
                $msg = '当前产品已停产，不可启用和上架！';
            }
        }

        if($rtstatus==0 && $is_shelved==1 && $is_enabled!=1){
            $rtstatus = 1;
            $msg = '产品选择上架，必须同时启用，请选择是否启用！';
        }

        if ($rtstatus==0 && ($institution_code != null && $institution_code != '') && ($goods_code != null && $goods_code != '')) {
            $rtstatus = Goods::updateInstGoods($institution_code, $goods_code, $settlement_price, $selling_price, $supply_price, $category_code, $is_enabled, $is_shelved, $shelve_datetime, $is_newest, $is_hot, $is_top, $is_show);
            //调用机构数据修改记录添加
            if(!InstitutionUpdateRecord::existRecord($institution_code,1)){
                InstitutionUpdateRecord::addRecord($institution_code,1);
            }
        }

        return $this->renderJson('', $rtstatus, $msg);
    }

    /**
     * 查询机构产品详情 instgoods-detail-part-view
     * @return string
     */
    public function actionInstgoodsDetailPartView()
    {
        $request = Yii::$app->request;
        $goods_code = $request->post("goods_code");
        $institution_code = $request->post("institution_code");

        $goods_detail = Goods::getGoodsInfoByCode($institution_code, $goods_code);

        return $this->renderPartial('instgoods-detail-part-view', ['goods' => $goods_detail]);
    }

    /**
     * 编辑机构产品详情 instgoods-detail-part-edit
     * @return string
     */
    public function actionInstgoodsDetailPartEdit()
    {
        $request = Yii::$app->request;
        $goods_code = $request->post("goods_code");
        $institution_code = $request->post("institution_code");

        $goods_detail = Goods::getGoodsInfoByCode($institution_code, $goods_code);

        $catelist = Goods::getGoodsCategoryList($institution_code);

        return $this->renderPartial('instgoods-detail-part-edit', ['goods' => $goods_detail, 'catelist' => $catelist]);
    }

    /**
     * 机构产品上下架操作 institution-goods-shelve-handler
     * @return string
     */
    public function actionInstitutionGoodsShelveHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $institution_code = $request->post("institution_code");
        $is_shelved = $request->post("is_shelved");
        $goods_code_list = $request->post("goods_code_list");

        if ($institution_code != null && $institution_code != '') {
            //查询机构下是否有产品
            $DataCount = Goods::getGoodsCountByfilters($institution_code);
            if ($DataCount > 0) {
                if ($goods_code_list != null && $goods_code_list != '' && count($goods_code_list) > 0) {
                    for ($i = 0; $i < count($goods_code_list); $i++) {
                        Goods::updateInstGoodsIshelve($institution_code, $is_shelved, $goods_code_list[$i]);
                    }
                } else {
                    Goods::updateInstGoodsIshelve($institution_code, $is_shelved);
                }

                //添加机构数据修改记录
                if(!InstitutionUpdateRecord::existRecord($institution_code,1)){
                    InstitutionUpdateRecord::addRecord($institution_code,1);
                }
            } else {
                $flag = 1;
                $msg = "当前机构无产品数据，操作失败！";
            }
        }

        return $this->renderJson(null, $flag, $msg);
    }

    /**
     * 机构产品启禁用操作 institution-goods-enabled-handler
     * @return string
     */
    public function actionInstitutionGoodsEnabledHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $institution_code = $request->post("institution_code");
        $is_enabled = $request->post("is_enabled");
        $goods_code_list = $request->post("goods_code_list");

        if ($institution_code != null && $institution_code != '') {
            //查询机构下是否有产品
            $DataCount = Goods::getGoodsCountByfilters($institution_code);
            if ($DataCount > 0 && $goods_code_list != null && $goods_code_list != '' && count($goods_code_list) > 0) {

                if ($goods_code_list != null && $goods_code_list != '' && count($goods_code_list) > 0) {
                    $cnshelvedGoods = '';//记录不可启用的产品
                    for ($i = 0; $i < count($goods_code_list); $i++) {

                        if($is_enabled==1){
                            $canshelved = Goods::checkGoodsCanShelved($goods_code_list[$i]);
                            //如果查询出不可以启用上架则不允许保存数据
                            if(!$canshelved){
                                $cnshelvedGoods = $cnshelvedGoods.','.$goods_code_list[$i];
                            }else{
                                Goods::updateInstGoodsIsEnabled($institution_code, $is_enabled, $goods_code_list[$i]);
                            }
                        }else{
                            Goods::updateInstGoodsIsEnabled($institution_code, $is_enabled, $goods_code_list[$i]);
                        }
                    }

                    if($cnshelvedGoods!=null && $cnshelvedGoods!=''){
                        $rtgoods = substr($cnshelvedGoods,1,strlen($cnshelvedGoods));
                        $msg = '以下商品已停产，启用失败！【'.$rtgoods.'】';
                    }

                    //添加机构数据修改记录
                    if(!InstitutionUpdateRecord::existRecord($institution_code,1)){
                        InstitutionUpdateRecord::addRecord($institution_code,1);
                    }
                } else {
                    $flag = 1;
                    $msg = "无可操作的产品，操作失败！";
                }

            } else {
                $flag = 1;
                $msg = "当前机构无产品数据，操作失败！";
            }
        }

        return $this->renderJson(null, $flag, $msg);
    }

    /**
     * 机构产品结算价变更确认
     */
    public function actionInstGoodsPriceChangeConfirm()
    {

        $request = Yii::$app->request;
        $institution_code = $request->post("institution_code");
        $goods_code = $request->post("goods_code");

        if ($institution_code != null && $institution_code != '') {
            Goods::confirmInstGoodsPriceChange($institution_code, $goods_code);
        }

        return $this->renderJson();
    }

    /**
     * goods-category
     * 商品分类
     */
    public function actionGoodsCategory()
    {
        $institution_code = Manager::getCurrentManager()['institution_code'];
//        if (Manager::getCurrentManager()['id'] == '0') {
        if ($institution_code == '0') {
            $inst = \Yii::$app->request->get('inst', '');
            if ($inst != '' || $inst != '0') {
                $institution_code = \Yii::$app->request->get('inst', '');
            }
        }

        $list = null;

        //返回时如果未选择机构则返回当前用户所属机构
        if ($institution_code == null || $institution_code == '') {
            //当前用户的机构-----------------------------------------------
            $current_console_user = Manager::getCurrentManager();
            $institution = $current_console_user['institution_code'];
            //---------------------------------------------------------------
            $institution_code = $institution;
        }

        if ($institution_code != null && $institution_code != '') {
            //查询分类LIST
            $list = Goods::getGoodsCategoryListbyParentCode($institution_code, null);
        }


        //返回结果
        return $this->render('goods-category', ['list' => $list, 'institution_code' => $institution_code]);
    }

    /**
     * 获取下级商品种类
     * @return string
     */
    public function actionGoodsCategoryChildView()
    {
        $this->layout = false;

        $institution_code = \Yii::$app->request->post('institution_code');
        $parent_code = \Yii::$app->request->post('parent_code');
        $list = Goods::getGoodsCategoryListbyParentCode($institution_code, $parent_code);

        return $this->render('goods-category-child-view', ['list' => $list]);
    }

    /**
     * 获取商品类型
     * @return string
     */
    public function actionGetGoodsCategoryHandler()
    {
        $code = \Yii::$app->request->post('code');
        $institution_code = \Yii::$app->request->post('institution_code');
        if($institution_code==null || $institution_code==''){
            $institution_code = Manager::getCurrentManager()['institution_code'];
        }
        $result = Goods::getGoodsCategory($institution_code, $code);
        return $this->renderJson($result, 0, '');
    }

    /**
     * syn-goods-category
     * 同步机构商品分类
     * @return string
     */
    public function actionSynGoodsCategoryHandler()
    {
        $msg = "";
        $flag = 0;
        //当前机构的上级机构产品信息
        $request = Yii::$app->request;
        $institution_code = $request->post("institution_code");

        if ($institution_code == null || $institution_code=='' || $institution_code == '0') {
            //同步系统商品分类
            Goods::synGoodsCategory();
        } else if ($institution_code != null && $institution_code != '' && $institution_code != '0') {
            //同步机构商品分类
            $flag = Goods::synInstGoodsCategory($institution_code);
        }

        return $this->renderJson(null, $flag, $msg);
    }

    /**
     * 保存商品分类 edit-goods-category-handler
     * @return string
     */
    public function actionEditGoodsCategoryHandler()
    {
        $msg = "";
        $flag = 0;
        //当前机构的上级机构产品信息
        $request = \Yii::$app->request;
        $code = $request->post("edit_code");
        $name = $request->post("edit_name");
        $parent_code = $request->post("edit_parent_code");
        $institution_code = $request->post("edit_institution_code");
        $image_url = $request->post("edit_image_url");
        $is_show_obj = $request->post("edit_is_show");
        $is_show = 0;
        if($is_show_obj==true){
            $is_show = 1;
        }

        $currentManager = Manager::getCurrentManager();
        if ($currentManager['id'] == '0' && $institution_code == '') {
            $institution_code = '0';
        }
        $rtcode = "";


        if ($institution_code != null && $institution_code != '') {

            //验证同一级下名称是否重复
            $checkIsRepeat = Goods::checkGoodsCategoryIsRepeat($institution_code, $code, $name, $parent_code);

            if($checkIsRepeat!=null && $checkIsRepeat!='' && $checkIsRepeat==1){
                $flag = 1;
                $msg = "在同一级另下名称不能重复！";
            }

            if($flag==0){
                //读取上传的图片文件
                if (isset($_FILES['edit_image_file'])) {
                    if ($_FILES["edit_image_file"]["error"] == 0) {
                        $fileName = Tools::uuid() . '.' . pathinfo($_FILES["edit_image_file"]["name"])['extension'];
                        $filePath = $_FILES["edit_image_file"]["tmp_name"];
                        $image_url = FileService::uploadImage($filePath, $fileName);
                    }
                }
                //保存商品分类
                $rtcode = Goods::editGoodsCategory($code, $name, $is_show, $image_url, $parent_code, $institution_code);

                //没有返回商品分类编号则视为没有操作成功
                if ($rtcode == null || $rtcode == '') {
                    $flag = 1;
                    $msg = "数据保存失败！";
                }else{
                    //删除操作成功记录机构操作记录
                    //调用机构数据修改记录添加
                    if(!InstitutionUpdateRecord::existRecord($institution_code,2)){
                        InstitutionUpdateRecord::addRecord($institution_code,2);
                    }
                }
            }

        }else{
            $flag = 1;
            $msg = "机构信息不能为空！";
        }


        return $this->renderJson(['rtcode' => $rtcode, 'image_url' => $image_url], $flag, $msg);
    }

    /**
     * 检查删除商品种类是否有下级种类 delete-goods-category-check-handler
     * @return string
     */
    public function actionDeleteGoodsCategoryCheckHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $code = $request->post("code");
        $institution_code = $request->post("institution_code");

        $rtstatus = '';
        if (($code != null && $code != '') && ($institution_code != null && $institution_code != '')) {
            //检查删除数据
            $rtstatus = Goods::deleteGoodsCategoryCheck($code, $institution_code);
        }

        if ($rtstatus != null &&  $rtstatus > 0) {
            $flag = 1;
            $msg = "该项含有下级种类，请先删除";
        }

        return $this->renderJson($rtstatus, $flag, $msg);
    }

    /**
     * 删除商品分类 delete-goods-category-handler
     */
    public function actionDeleteGoodsCategoryHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $code = $request->post("code");
        $institution_code = $request->post("institution_code");

        $rtstatus = '';
        if (($code != null && $code != '') && ($institution_code != null && $institution_code != '')) {
            //删除数据
            $rtstatus = Goods::deleteGoodsCategory($code, $institution_code);
        }

        if ($rtstatus == 0 || $rtstatus == null || $rtstatus == false) {
            $flag = 1;
            $msg = "操作失败";
        }else{
            //删除操作成功记录机构操作记录
            //调用机构数据修改记录添加
            if(!InstitutionUpdateRecord::existRecord($institution_code,2)){
                InstitutionUpdateRecord::addRecord($institution_code,2);
            }
        }

        return $this->renderJson([], $flag, $msg);
    }

    //////////////////////////////商品扩展分类--start//////////////////////////////////////////////////////////////////////
    /**
     * goods-extend-category
     * 商品扩展分类
     */
    public function actionGoodsExtendCategory()
    {
        $institution_code = Manager::getCurrentManager()['institution_code'];

        if ($institution_code == '0') {
            $institution_code = Yii::$app->request->get('inst', '');
        }
        //返回时如果未选择机构则返回当前用户所属机构
        if ($institution_code == null || $institution_code == '') {
            //当前用户的机构-----------------------------------------------
            $current_console_user = Manager::getCurrentManager();
            $institution = $current_console_user['institution_code'];
            //---------------------------------------------------------------
            $institution_code = $institution;
        }
        $list = [];
        if ($institution_code != null && $institution_code != '') {
            //查询分类LIST
            $list = Goods::getGoodsExtendCategoryList($institution_code);
        }


        //返回结果
        return $this->render('goods-extend-category', ['list' => $list, 'institution_code' => $institution_code]);
    }

    /**
     * 商品扩展分类新增 编辑 VIEW goods-extend-category-part-view
     */
    public function actionGoodsExtendCategoryPartView()
    {
        $request = Yii::$app->request;
        $institution_code = $request->post("institution_code");
        $id = $request->post("id");

        //详情
        $detail = '';

        if (($id != null && $id != '') && ($institution_code != null && $institution_code != '')) {
            $detail = Goods::getGoodsExtendCategoryDetails($id, $institution_code);
        }

        return $this->renderPartial('goods-extend-category-part-view', ['institution_code' => $institution_code, 'detail' => $detail]);
    }

    /**
     * 商品扩展分类   分类产品设置  VIEW goods-extend-category-goods-part-view
     */
    public function actionGoodsExtendCategoryGoodsPartView()
    {
        $request = Yii::$app->request;
        $id = $request->post("id");
        //清理非本机构所属产品
        Goods::clearGoodsExtendCategoryGoods($id);
       $categoryV1=Goods::getGoodsCategoryByLength($id,2);
        $institution_code=Goods::getInstitutionCodeByGoods_extend_categoryId($id);
       $extendCategoryType2=Goods::getGoodsExtendCategoryList($institution_code,2);
        $NcTagList=Goods::getGoodsTagUsedList();
        return $this->renderPartial('goods-extend-category-goods-part-view', [
            'id' => $id,
            'categoryV1'=>$categoryV1,
            'extendCategoryType2'=>$extendCategoryType2,
            'NcTagList'=>$NcTagList,
        ]);
    }

    /**获取下一级商品分类列表
     * @return string
     * get-next-level-goods-category
     */
    public function actionGetNextLevelGoodsCategory(){
        $request = Yii::$app->request;
        $id = $request->post("id");
        $code = $request->post("code");
        $institution_code=Goods::getInstitutionCodeByGoods_extend_categoryId($id);
        $list=Goods::getGoodsCategoryNext($institution_code,$code);
        return $this->renderJson($list);
    }

    /**
     * goods-extend-category-goods-table-view
     * @return string
     */
    public function actionGoodsExtendCategoryGoodsTableView()
    {
        $this->layout = false;
        $request = Yii::$app->request;
        $id = $request->post("id");
        $code = $request->post("code");
        $name = $request->post("name");
        $brand = $request->post("brand");
        $selected = $request->post("selected");
        $categoryV1 = $request->post("categoryV1");
        $categoryV2 = $request->post("categoryV2");
        $categoryV3 = $request->post("categoryV3");
        $priceS = $request->post("priceS");
        $priceE = $request->post("priceE");
        $extend_category = $request->post("extend_category");
        $ncTagId = $request->post("ncTagId");

        $goodslist = Goods::getGoodsExtendCategoryGoods($id, $code, $name, $brand, $selected,$categoryV1,$categoryV2,$categoryV3,$priceS,$priceE,$extend_category,$ncTagId);
//        var_dump($goodslist);exit;
        return $this->renderPartial('goods-extend-category-goods-table-view', ['goodslist' => $goodslist]);
    }

    /**
     * 设置扩展分类产品 goods-extend-category-goods-set
     * @return string
     */
    public function actionGoodsExtendCategoryGoodsSet()
    {
        $request = Yii::$app->request;
        $extend_category_id = $request->post("extend_category_id");
        $institution_code = $request->post("institution_code");
        $goods_code = $request->post("goods_code");

        $selected = $request->post("selected");

        if ($selected=='1') {
            Goods::addGoodsExtendCategoryGoods($extend_category_id, $goods_code);
        } else {
            Goods::delGoodsExtendCategoryGoods($extend_category_id, $goods_code);
        }
        //调用机构数据修改记录添加
        if(!InstitutionUpdateRecord::existRecord($institution_code,1)){
            InstitutionUpdateRecord::addRecord($institution_code,1);
        }
        if(!InstitutionUpdateRecord::existRecord($institution_code,3)){
            InstitutionUpdateRecord::addRecord($institution_code,3);
        }

        return $this->renderJson('');
    }
    /**
     * 设置扩展分类产品 goods-extend-category-goods-set-bat
     * @return string
     */
    public function actionGoodsExtendCategoryGoodsSetBat()
    {
        $request = Yii::$app->request;
        $extend_category_id = $request->post("extend_category_id");
        $institution_code = $request->post("institution_code");
        $goods_codes = $request->post("goods_codes");

        $selected = $request->post("selected");

        if ($selected=='1') {
            Goods::addGoodsExtendCategoryGoodsBat($extend_category_id, $goods_codes);
        } else {
            Goods::delGoodsExtendCategoryGoodsBat($extend_category_id, $goods_codes);
        }
        //调用机构数据修改记录添加
        if(!InstitutionUpdateRecord::existRecord($institution_code,1)){
            InstitutionUpdateRecord::addRecord($institution_code,1);
        }
        if(!InstitutionUpdateRecord::existRecord($institution_code,3)){
            InstitutionUpdateRecord::addRecord($institution_code,3);
        }

        return $this->renderJson('');
    }
    /**
     * 设置扩展分类产品是否首页显示 goods-extend-category-goods-is-index-show-set
     * @return string
     */
    public function actionGoodsExtendCategoryGoodsIsIndexShowSet()
    {
        $request = Yii::$app->request;
        $extend_category_id = $request->post("extend_category_id");
        $institution_code = $request->post("institution_code");
        $goods_code = $request->post("goods_code");

        $selected = $request->post("selected");

        if ($selected=='1') {
            Goods::setGoodsExtendCategoryGoodsIsIndexShow($extend_category_id, $goods_code,1);
        } else {
            Goods::setGoodsExtendCategoryGoodsIsIndexShow($extend_category_id, $goods_code,0);
        }
        //调用机构数据修改记录添加
        if(!InstitutionUpdateRecord::existRecord($institution_code,1)){
            InstitutionUpdateRecord::addRecord($institution_code,1);
        }
        if(!InstitutionUpdateRecord::existRecord($institution_code,3)){
            InstitutionUpdateRecord::addRecord($institution_code,3);
        }

        return $this->renderJson('');
    }
    /**
     * syn-goods-extend-category-handler
     * 同步机构商品扩展分类
     * @return string
     */
    public function actionSynGoodsExtendCategoryHandler()
    {
        $msg = "";
        $flag = 0;
        //当前机构的上级机构产品信息
        $request = Yii::$app->request;
        $institution_code = $request->post("institution_code");

        if ($institution_code == null || $institution_code == '0') {
            $msg = "必须选择一个机构";
            $flag = 1;
        } else if ($institution_code != null && $institution_code != '' && $institution_code != '0') {
            //同步机构商品分类
            $re = Goods::synGoodsGoodsCategory($institution_code);
            if ($re == '10') {
                $msg = "没有上一级机构";
                $flag = 1;
            } else {
                $flag = $re;
            }
        }

        return $this->renderJson(null, $flag, $msg);
    }

    /**
     * 保存商品扩展分类 edit-goods-extend-category
     * @return string
     */
    public function actionEditGoodsExtendCategory()
    {
        //当前机构的上级机构产品信息
        $request = Yii::$app->request;

        $id = $request->post("edit_id");
        $institution_code = $request->post("edit_institution_code");
        $name = $request->post("edit_name");
        $identifier_code = $request->post("edit_identifier_code");
        $type = $request->post("edit_type");
        $image_url = $request->post("edit_image_url");
        $link_url = $request->post("edit_link_url");
        $summary = $request->post("edit_summary");
        $is_enabled = $request->post("edit_is_enabled");
        $remark = $request->post("edit_remark");
        $endpoint = $request->post("edit_endpoint");

        $currentManager = Manager::getCurrentManager();
        if ($currentManager['id'] == '0' && $institution_code == '') {
            $institution_code = '0';
        }
        if ($institution_code != null && $institution_code != '') {

            //检查数据
            if (empty($id)) {
                if (Goods::editGoodsExtendCategory_check_name($institution_code, $name) == false) {
                    echo $this->renderJson([], 1, '分类名称不能重复');
                    exit;
                }
                if ($identifier_code) {
                    if (Goods::editGoodsExtendCategory_check_identifier_code($institution_code, $identifier_code) == false) {
                        echo $this->renderJson([], 1, '分类定义标识符不能重复');
                        exit;
                    }
                }
            }
            //读取上传的图片文件
            if (isset($_FILES['edit_image_file'])) {
                if ($_FILES["edit_image_file"]["error"] == 0) {
                    $fileName = Tools::uuid() . '.' . pathinfo($_FILES["edit_image_file"]["name"])['extension'];
                    $filePath = $_FILES["edit_image_file"]["tmp_name"];
//                    $uploadResult = Cosapi::upload($filePath, Conf::BucketName(), Conf::dstPath($fileName));
//                    if ($uploadResult['code'] == 0) {
//                        $image_url = $uploadResult['data']['access_url'];
//                    }
                    $image_url = FileService::uploadImage($filePath, $fileName);
                }
            }

            //保存商品扩展分类
            $id = Goods::editGoodsExtendCategory($id, $name, $institution_code, $summary, $image_url, null, $type, $link_url, $remark, $is_enabled, $identifier_code,$endpoint);

            //调用机构数据修改记录添加
            if(!InstitutionUpdateRecord::existRecord($institution_code,3)){
                InstitutionUpdateRecord::addRecord($institution_code,3);
            }
        }


        echo $this->renderJson(['id' => $id, 'image_url' => $image_url]);
    }

    /**
     * 删除商品扩展分类 delete-goods-extend-category-handler
     */
    public function actionDeleteGoodsExtendCategoryHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $id = $request->post("id");
        $institution_code = $request->post("institution_code");

        if (($id != null && $id != '') && ($institution_code != null && $institution_code != '')) {
            //删除数据
            $re = Goods::deleteGoodsExtendCategory($id);
            if ($re == false) {
                $flag = 1;
                $msg = "操作失败";
            }else{
                //调用机构数据修改记录添加
                if(!InstitutionUpdateRecord::existRecord($institution_code,3)){
                    InstitutionUpdateRecord::addRecord($institution_code,3);
                }
            }
        }


        return $this->renderJson([], $flag, $msg);
    }
    ///////////////////////////////商品扩展分类--end///////////////////////////////////////////////////////////////////////

    /**
     * 商品针对旗下机构不可见(列表查询)
     * goods-hide
     * @return string
     */
    public function actionGoodsHide()
    {
        $page = Yii::$app->request->get('page', 1);
        $institution_code = Yii::$app->request->get('institution_code', '');
        $child_institution_code = Yii::$app->request->get('child_institution_code', '');

        $DataCount = 0;
        $PageSize = 10;
        $list = null;

        //返回时如果未选择机构则返回当前用户所属机构
        if ($institution_code == null || $institution_code == '') {
            //当前用户的机构-----------------------------------------------
            $current_console_user = Manager::getCurrentManager();
            $institution = $current_console_user['institution_code'];
            //---------------------------------------------------------------
            $institution_code = $institution;
        }


        if ($institution_code != null && $institution_code != '') {
            //取得商品针对旗下机构不可见数据总数 -用于分页
            $DataCount = Goods::getGoodsHideChildCountByfilters($institution_code, $child_institution_code);
            //查询结果
            $list = Goods::getGoodsHideChildListByfilters($institution_code, $child_institution_code, $page, $PageSize);
        }

        $pagination = new Pagination([
            'defaultPageSize' => $PageSize,
            'totalCount' => $DataCount,
        ]);

        //返回结果
        return $this->render('goods-hide', ['pagination' => $pagination, 'list' => $list
            , 'institution_code' => $institution_code, 'child_institution_code' => $child_institution_code]);
    }

    /**
     * 获取有下级机构的上级机构列表 get-super-institution
     * @return string
     */
    public function actionGetSuperInstitutionHandler()
    {
        $superior_inst_list = Goods::getInstitutionCatalog();

        return $this->renderJson(['superinst' => $superior_inst_list]);
    }

    /**
     * 获取下级机构列表 get-child-institution
     * @return string
     */
    public function actionGetChildInstitutionHandler()
    {
        $request = Yii::$app->request;
        $institution_code = $request->post("institution_code");

        $childinst = Goods::getChildInstitution($institution_code);

        return $this->renderJson(['childinst' => $childinst]);
    }

    /**
     * 旗下机构不可见商品设置VIEW  hide-child-inst-part-view
     * @return string
     */
    public function actionHideChildInstPartView()
    {
        $request = Yii::$app->request;
        $super_inst_code = $request->post("super_inst_code");

        //通过上级机构编号取得下级机构列表
        $childinst = Goods::getChildInstitution($super_inst_code);

        return $this->renderPartial('hide-child-inst-part-view', ['super_inst_code' => $super_inst_code, 'childinst' => $childinst]);
    }

    /**
     * import-hide-child-inst-confirm
     * 旗下机构不可见商品设置-导入确认
     * @return string
     */
    public function actionImportHideChildInstConfirmHandler()
    {
        $request = Yii::$app->request;
        $hideGoodsList = $request->post("hideGoodsList");

        if ($hideGoodsList != null && $hideGoodsList != '') {
            foreach ($hideGoodsList as $hideGoods) {
                $super_inst_code = $hideGoods['super_inst_code'];
                $child_inst_code = $hideGoods['child_inst_coed'];
                $goods_code = $hideGoods['goods_code'];
                $is_hide = $hideGoods['is_hide'];
                $is_hide_boolean = null;
                if ($super_inst_code == null || $super_inst_code == '') {
                    $super_inst_code = '0';
                }
                if ($is_hide != null && $is_hide == '是') {
                    $is_hide_boolean = "true";
                } else {
                    $is_hide_boolean = "false";
                }
                $rtstatus = Goods::changeHideChildInst($super_inst_code, $child_inst_code, $goods_code, $is_hide_boolean);
            }
        }

        return $this->renderJson('');
    }

    /**
     * import-hide-child-inst
     * 旗下机构不可见商品设置-导入
     */
    public function actionImportHideChildInst()
    {
        $status = 0;
        $msg = '';
        $goods_list = array();
        $file = $_FILES['file']['name'];
        if (empty($file)) {
            $status = 1;
            $msg = json_encode("请选择要上传的文件");
        } else {
            $file_info = pathinfo($file);
            $file_ext = $file_info['extension'];
            if (!in_array($file_ext, array('xls', 'xlsx'))) {
                $status = 1;
                $msg = json_encode("文件类型不正确，仅支持xls,xlsx类型的文件！");
            } else {
                $objPHPExcel = \PHPExcel_IOFactory::load($_FILES['file']['tmp_name']);
                $sheet = $objPHPExcel->getSheet(0);
                $highestRow = $sheet->getHighestRow();       //取得总行数
                $highestColumn = $sheet->getHighestColumn(); //取得总列

                if ($highestRow > 5002) {
                    $status = 2;
                    $msg = json_encode("一次导入数据不能超过5000条记录！");
                } else {

                    for ($j = 2; $j <= $highestRow; $j++)                      //从第二行开始读取数据
                    {
                        $is_error = 0;
                        $v = array();

                        for ($k = 'A'; $k <= $highestColumn; $k++)            //从A列读取数据
                        {
                            $value = $objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue();//读取单元格
                            $v['error'] = "";

                            //获取数据
                            switch ($k) {
                                case 'A':
                                    $v['super_inst_code'] = '0';
                                    $v['super_inst_name'] = trim($value);
                                    break;
                                case 'B':
                                    $v['goods_code'] = trim($value);
                                    break;
                                case 'C':
                                    $v['goods_name'] = trim($value);
                                    break;
                                case 'D':
                                    $v['child_inst_coed'] = trim($value);
                                    break;
                                case 'E':
                                    $v['child_inst_name'] = trim($value);
                                    break;
                                case 'F':
                                    $v['is_hide'] = trim($value);
                                    break;
                            }

                        }

                        $errormsg = "";
                        //检查数据有效性

                        //检查上级机构是否存在
                        $instcode = '';
                        if ($v['super_inst_name'] != null && $v['super_inst_name'] != '无') {
                            $inst = Institution::getInstCodeByNameOrCode(null, $v['super_inst_name']);
                            if ($inst == null || $inst == '') {
                                $errormsg = ">上级机构【" . $v['super_inst_name'] . "】不存在！";
                            } else {
                                //取得上级机构编码
                                $instcode = $inst[0]['code'];
                                $v['super_inst_code'] = $instcode;//取得上级机构编码反回
                            }
                        }

                        //检查下级机构信息 01下级机构是否存在 02下级机构对应上级机构是否与导入的相同
                        $childinst = Institution::getInstCodeByNameOrCode($v['child_inst_coed'], $v['child_inst_name']);
                        if ($childinst == null || $childinst == '') {
                            $sign = "";
                            if ($errormsg != null && $errormsg != '') {
                                $sign = "<br>";
                            }
                            $errormsg = $errormsg . $sign . ">旗下机构【" . $v['child_inst_name'] . "】不存在，或者编码与名称不对应！";
                        } else {
                            $parent_name = $childinst[0]['parent_name'];
                            if ($parent_name != $v['super_inst_name']) {
                                $sign = "";
                                if ($errormsg != null && $errormsg != '') {
                                    $sign = "<br>";
                                }
                                $errormsg = $errormsg . $sign . ">旗下机构【" . $v['child_inst_name'] . "】对应的上级机构为【" . $parent_name . "】，与导入的不符，请确认！";
                            }
                        }

                        if ($instcode != null && $instcode != '' && $v['goods_code'] != null && $v['goods_code'] != '') {
                            $goodscode = Goods::getGoodsCodeByInstAndCode($instcode, $v['goods_code']);
                            if ($goodscode == null || $goodscode == '') {
                                $sign = "";
                                if ($errormsg != null && $errormsg != '') {
                                    $sign = "<br>";
                                }
                                $errormsg = $errormsg . $sign . ">机构【" . $v['super_inst_name'] . "】下不存在产品【" . $v['goods_code'] . "】,请确认！";
                            }
                        }

                        if ($errormsg != null && $errormsg != '') {
                            $v['error'] = $errormsg;
                        }

                        $goods_list[] = $v;
                    }
                }
            }
        }

        return $this->renderJson(['goods_list' => $goods_list], $status, $msg);
    }

    /**
     * 旗下机构不可见商品设置 产品查询VIEW  hide-child-inst-part-goods
     * @return string
     */
    public function actionHideChildInstPartGoods()
    {
        $this->layout = false;
        $request = Yii::$app->request;
        $super_inst_code = $request->post("super_inst_code");
        $chiled_inst_code = $request->post("chiled_inst_code");
        $code = $request->post("code");
        $name = $request->post("name");
        $brand = $request->post("brand");
        $is_hide = $request->post("is_hide");

        //通过传入的 上下级机构 产品编号 名称 品牌条件查询出上级机构的产品列表 以及当前机构是否可见状态
        $goodslist = Goods::getChildHideInstGoods($super_inst_code, $chiled_inst_code, $code, $name, $brand, $is_hide);

        return $this->renderPartial('hide-child-inst-part-goods', ['goodslist' => $goodslist]);
    }

    /**
     * 变更商品针对旗下机构不可见 change-hide-child-inst
     * @return string
     */
    public function actionChangeHideChildInstHandler()
    {
        $request = Yii::$app->request;
        $super_inst_code = $request->post("super_inst_code");
        $child_inst_code = $request->post("child_inst_code");
        $goods_code = $request->post("goods_code");
        $is_hide = $request->post("is_hide");

        $rtstatus = Goods::changeHideChildInst($super_inst_code, $child_inst_code, $goods_code, $is_hide);

        return $this->renderJson('', $rtstatus);
    }
    /**nc扩展分类**/
    public function actionGoodsTag($tag_Id='',$pageSize=10){
        $totalCount=Goods::getGoodsTagGoodsList($tag_Id,0,0,'count');
        $pagination = new Pagination([
            'defaultPageSize' => $pageSize,
            'totalCount' => $totalCount,
        ]);
        $list=Goods::getGoodsTagGoodsList($tag_Id,$pagination->offset, $pagination->limit,'list');

        $tagList=Goods::getGoodsTagUsedList();
        return $this->render('goods-tag',[
            'list'=>$list,
            'tagList'=>$tagList,
            'tag_Id'=>$tag_Id,
            'pagination' => $pagination,
        ]);
    }

    /**
     * 同步nc扩展分类
     * syn-goods-tag-handle
     */
    public function actionSynGoodsTagHandle(){
        $msg = "";
        Goods::synGoodsTag();
        return $this->renderJson(null, 0, $msg);
    }
}